<template>
  <view class="blankpay-page">
    <image class="logo-img" :src="$getImg('iassBlankCashier/nbcb.jpg')" mode="aspectFill" />
    <view class="load-text">加载中...</view>
  </view>
</template>

<script>
  import {
    getOrderInfo,
    getPayOrder
  } from "@/pages/iassBlankCashier/api/index.js";
  import {
    isEmpty,
    getAuthCode
  } from "@/common/util.js"
  import {
    callPayment
  } from "@/pages/iassCashier/api/pay.js";
  import {
    mapGetters
  } from 'vuex';
  export default {
    data() {
      return {
        token: '',
        // outOrderNo: '',
        orderNo: '',
        authCode: '',
      };
    },
    computed: {
      ...mapGetters(["configInfo", "channelType"]),
    },
    onLoad(op) {
      uni.hideHomeButton()
      let options = uni.getEnterOptionsSync();
      if (!isEmpty(options) && !isEmpty(options.query)) {
        this.token = options.query.token || '';
        // this.outOrderNo = options.query.orderNo || '';
        this.orderNo = options.query.outOrderNo || '';
        // this.token = '/314102583980000/2024020609111754674190549651456u';
        this.queryOrderInfo()
      } else {
        uni.redirectTo({
          url: '/pages/iassCashier/error?errMsg=请扫描商家收款码进入',
        })
      }
    },
    methods: {
      async queryOrderInfo() {
        try {
          let codeRes = await getAuthCode();
          this.authCode = codeRes.code;
          let data = {
            codeId: this.token,
            authCode: this.authCode,
            channelType: this.channelType,
          }
          const result = await getOrderInfo(data)
          let payData = {
            token: this.token,
            authCode: this.authCode,
            payChannel: this.channelType,
          }
          this.callPayforOrder(payData, {
            totalFee: result.totalFee,
            cnAbber: result.cnAbbr,
          })
        } catch (err) {
          this.$toast(err.respMsg || '系统异常')
        }
      },
      async callPayforOrder(data, info) {
        try {
          let codeRes = await getPayOrder(data);
          codeRes.totalFee = info.totalFee
          codeRes.cnAbber = info.cnAbber
          codeRes.orderNo = this.orderNo
          callPayment(codeRes)
        } catch (err) {
          this.$toast(err.respMsg || '系统异常')
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .blankpay-page {
    min-height: 100vh;
    background-color: #fff;
    padding-top: 140rpx;

    .logo-img {
      display: block;
      margin: 0 auto;
      animation: rotate 3s linear infinite;
      height: 200rpx;
      width: 200rpx;
    }

    .load-text {
      text-align: center;
      font-size: 32rpx;
      line-height: 40rpx;
      color: #333;
      margin-top: 40rpx;
    }

    @keyframes rotate {
      to {
        transform: rotate(360deg);
      }
    }
  }
</style>